using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using Needle.Utils.Extensions;
using Needle.Utils.Parser;
using System.Reflection;

namespace Needle.Templates
{
    public class TemplateOptions
    {

        public string Language { get; set; }

        private IList<Property> _properties;
        public IList<Property> Properties
        {
            get
            {
                if (_properties == null)
                    _properties = new List<Property>();
                return _properties;
            }
        }

        private IList<AssemblyName> _referencedAssemblies;
        public IList<AssemblyName> ReferencedAssemblies
        {
            get
            {
                if (_referencedAssemblies == null)
                    _referencedAssemblies = new List<AssemblyName>();
                return _referencedAssemblies;
            }
        }

        private IList<String> _importedNamespaces;
        public IList<String> ImportedNamespaces
        {
            get {
                if (_importedNamespaces == null)
                    _importedNamespaces = new List<string>();
                return _importedNamespaces; }
        }

        private OutputOptions _output;
        public OutputOptions Output
        {
            get
            {
                if (_output == null)
                    _output = new OutputOptions();
                return _output;
            }
        }

    }

    public class Property
    {
        /// <summary>
        /// Initializes a new instance of the Property class.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="type"></param>
        public Property(string name, Type type)
        {
            _name = name;
            _type = type;
            _hasInitialValue = false;
        }
        public Property(string name, Type type, object initValue)
        {
            _name = name;
            _type = type;
            _initValue = initValue;
            _hasInitialValue = true;
        }

        private string _name;
        public string Name  
        {
            get { return _name; }
        }
        private Type _type;
        public Type Type
        {
            get { return _type; }
        }
        
        private bool _hasInitialValue;
        public bool HasInitialValue
        {
            get { return _hasInitialValue; }
        }
        
        private object _initValue;
        public object InitValue
        {
            get { return _initValue; }
        }

        public override bool Equals(object obj)
        {
            if (!(obj is Property))
                return false;
            Property p = (Property)obj;
            return Name == p.Name && Type == p.Type;
        }

        public override int GetHashCode()
        {
            return Name.GetHashCode() ^ Type.GetHashCode();
        }

        public override string ToString()
        {
            return String.Format("{0} ({1}) = {2}", Name, Type, InitValue);
        }
    }

    public class OutputOptions
    {
        public Encoding Encoding { get; set; }
        public String Name { get; set; }
    }
}

